import { lockStatus_text_mapping, lockStatus_tips } from "./const";
export function generateColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    {
      type: "selection",
      width: 60,
      align: "center"
    },
    {
      title: this.$t("module.userManage.userAccount"), // 用户账号
      key: "userId",
      sortable: "custom",
      minWidth: 100,
      maxWidth: 100 + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    {
      title: this.$t("module.userManage.name"), // 用户名称
      key: "userName",
      sortable: "custom",
      minWidth: 90,
      maxWidth: 90 + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    // {
    //   title: this.$t("module.userManage.type"), // 用户类型
    //   key: "category",
    //   minWidth: 90,
    //   render: (h, params) => {
    //     return h("span", this.switchCategory(params.row.category));
    //   }
    // },
    {
      title: this.$t("module.userManage.cellPhoneNumber"), // 手机号码
      key: "mobile",
      align: "center",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_MOBILE,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_MOBILE + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    {
      title: this.$t("module.userManage.email"), // 电子邮件
      key: "email",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_EMAIL,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_EMAIL + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    {
      title: this.$t("module.userManage.associatedStaffNumber"), // 关联员工编号
      key: "employeeId",
      minWidth: 110,
      maxWidth: 110 + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    // {
    //   title: this.$t("module.userManage.assignedRole"), // 所分配角色
    //   key: "roleNames",
    //   minWidth: 90,
    //   render: (h, params) => {
    //     return h("span", this.switchRoleName(params.row.roleNames));
    //   }
    // },
    // {
    //   title: this.$t("module.userManage.deptName"), // 组织部门
    //   key: "type",
    //   render: (h, params) => {
    //     return h("span", this.userTypeText(params.row.deptName));
    //   }
    // },
    // {
    //   title: this.$t("module.userManage.tenantName"), // 所属租户
    //   key: "tenantCode",
    //   minWidth: 120,
    //   render: (h, params) => {
    //     return h("span", this.getTenantName(params.row));
    //   }
    // },
    {
      title: this.$t("module.userManage.type"), // 用户类型
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_5_WORDS,
      render: (h, params) => {
        return h("span", this.getSourceName(params.row.type));
      }
    },
    // {
    //   title: this.$t("module.userManage.buName"),
    //   key: "buCode"
    // },
    {
      title: this.$t("common.status"), // 状态
      align: "center",
      key: "locked",
      minWidth: 80,
      maxWidth: 80 + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            // 修改StatusButton内容居中
            style: {
              "justify-content": "center"
            },
            props: {
              status: params.row.locked
            }
          },
          this.$t(lockStatus_text_mapping[params.row.locked])
        );
      }
    },
    {
      title: this.$t("common.operating"), // 操作按钮
      align: "left",
      fixed: "right",
      width: 100,
      render: (h, params) => {
        const ldapTypes = [4, 5]
        const hideEditBtn = ldapTypes.includes(params?.row?.type) && params?.row?.locked === '1'
        const hideLockAndUnlockBtn = ldapTypes.includes(params?.row?.type)
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "md-create",
                text: this.$t("common.edit"),
                hidden: hideEditBtn,
                handle: () => {
                  this.editUserInfo(params.row);
                }
              },
              {
                type: "icon",
                icon: params.row.locked === "0" ? "md-close" : "md-checkmark",
                text: this.$t(lockStatus_tips[params.row.locked === "0" ? "1" : "0"]),
                // hidden: params.row.userName == "admin" ? true : false,
                hidden: hideLockAndUnlockBtn || params.row.userName == "admin" ? true : false,
                permission: "USER_INDEX",
                handle: () => {
                  this.changeStatus(params.row);
                }
              },
              {
                type: "icon",
                icon: "md-unlock",
                text: this.$t("module.userManage.unlockUser"),
                hidden: !(params.row.loginLocked && this.isAdmin),
                permission: "USER_INDEX",
                handle: () => {
                  this.unlock(params.row);
                }
              }
            ]
          }
        });
      }
    }
  ];
}
export function employeeColomns() {
  return [
    {
      title: this.$t("module.userManage.employeeNo"),
      key: "employeeNo"
    },
    {
      title: this.$t("module.userManage.employeeName"),
      key: "employeeName"
    },
    {
      title: this.$t("module.userManage.employDepartment"),
      key: "employeeOrgPath"
    }
  ];
}
export function ldapColumns() {
  return [
    {
      type: "selection",
      width: 60,
      align: "center"
    },
    {
      title: this.$t("module.userManage.userAccount"), // 用户账号
      key: "userId",
      minWidth: 100
    },
    {
      title: this.$t("module.userManage.name"), // 用户名称
      key: "userName",
      minWidth: 90
    },
    {
      title: this.$t("module.userManage.cellPhoneNumber"), // 手机号码
      key: "mobile",
      minWidth: 110
    },
    {
      title: this.$t("module.userManage.email"), // 电子邮件
      key: "email",
      minWidth: 90
    },
    {
      title: this.$t("module.userManage.orgNum"), // 组织编号
      key: "setId",
      minWidth: 110
    },
    {
      title: this.$t("module.userManage.deptCode"), // 部门编码
      key: "deptId",
      minWidth: 90

    }
  ];
}
export function selectLdapColumns() {
  return [
    {
      title: this.$t("module.userManage.userAccount"), // 用户账号
      key: "userId",
      minWidth: 100
    },
    {
      title: this.$t("module.userManage.name"), // 用户名称
      key: "userName",
      minWidth: 90
    },
    {
      title: this.$t("module.userManage.cellPhoneNumber"), // 手机号码
      key: "mobile",
      minWidth: 110
    },
    {
      title: this.$t("module.userManage.email"), // 电子邮件
      key: "email",
      tooltip: true,
      minWidth: 90
    },
    {
      title: this.$t("common.operating"), // 操作按钮
      align: "left",
      fixed: "right",
      width: 60,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "md-close",
                text: this.$t("common.delete"),
                handle: () => {
                  this.deleteUser(params.row);
                }
              }
            ]
          }
        });
      }
    }
  ];
}
